<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
 *
 *
 *
 * @package     h
 * @subpackage  models
 * @category    models
 * @author      hyw
 * @copyright   copyright (c) 2012
 * @filesource
 */
class Department_model extends Base_model {
    protected $_table_name = 'department';
    protected $_key_name = 'department_id';
	
	function get_info($id) {
		if(!empty($id))
			$where[$this->_key_name]=$id;
		$where["dtime"]=0;
		return $this->fetch(NULL, $where,NULL,'row');
	}

    function get_all() {
		$this->set_order_by('sequence,ASC');
		$where=array("dtime"=>0);
		return $this->fetch(NULL, $where);
    }
	
	function query_keyword($keyword="",$limit) 
	{
		$this->set_or_like('department_name,explanation',$keyword);
		$this->set_limit($limit);
		$where=array($this->_key_name=>0);
		return $this->fetch(NULL, $where);
    }
	
	function query_keyword_count($keyword=null)
	{
		$this->set_or_like('department_name,explanation',$keyword);
		$con["where"][] = array("dtime"=>0);
        $this->set_args_array($con);
        return $this->fetch_count();
	}
	
	function update_data($data) {
		$value=array('department_name'=>$data['department_name'],'explanation'=>$data['explanation'],'mtime'=>time());
		$where[]=array($this->_key_name=>$data['id']);
		return $this->update($value, $where);
	}
	function add($data) {		
		$data["ctime"]=time();
		return $this->insert ( $data );
	}

	function del($data) {
		$where[]=array($this->_key_name=>$data['id']);
		$value=array("dtime"=>time());
		return $this->update($value, $where);
	}
	
	
	
	
}